# 给定一个数组 candidates 和一个目标值 target，返回 candidates 中所有和为 target 的组合。
def solve(candidates: list[int], target: int):
    path = []
    result = []
    def backtracking(startindex):
        if sum(path) == target:
            result.append(path[:])
            return
        if sum(path) > target:
            return
        for i in range(startindex+1,len(candidates)):
            path.append(candidates[i])
            backtracking(i)
            path.pop()
    backtracking(-1)
    return result

if __name__ == "__main__":
    print(solve([2,2,3,6,7],7))